using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using EOffice.Business;


namespace EOffice.Presentation
{
    public partial class ctrPublicRoom : UserControl
    {
        private String[] Messages;
        private string LocalUser;
        private int MessageNumber = 100;
        public event EventHandler NotifyDaddy;
        public event EventHandler NotifyPrivate;
        public event EventHandler NotifyEnter;
        public event EventHandler NotifyBecomeOnline;

        public ctrPublicRoom(string username)
        {
            InitializeComponent();
            this.Text += " - " + username;
            Messages = new String[MessageNumber + 5];
        }

        public string localuser
        {
            set { LocalUser = value; }
            get { return LocalUser; }
        }
        public ctrPublicRoom()
        {
            InitializeComponent();
            Messages = new String[MessageNumber + 5];
        }

        protected void OnNotifyEnter(string mes)
        {
            if (NotifyEnter != null) NotifyEnter(this, new NotifyEnterEventArgs(mes));
        }

        // Wire up the event
        protected void OnNotifyDaddy(string mes)
        {
            if (NotifyDaddy != null) NotifyDaddy(this, new NotifyDaddyEventArgs(mes));
        }

        protected void OnNotifyPrivate(string name)
        {
            if (NotifyPrivate != null) NotifyPrivate(this, new NotifyPrivateEventArgs(name));
        }

        protected void OnNotifyBecomeOnline(string name)
        {
            if (NotifyBecomeOnline != null) NotifyBecomeOnline(this, new NotifyBecomeOnlineEventArgs(name));
        }

        private void btnSend_Click(object sender, System.EventArgs e)
        {
            this.OnNotifyDaddy(txtChat.Text);
            txtChat.Clear();
        }

        public void DeleteTextBox3()
        {
            try
            {
                lstUser.Items.Clear();
            }
            catch { }

        }

        public void WriteMessage(String data, int color, int font, int BItype)
        {
            if (color == 5)
            {
                txtContentMsg.ForeColor = Color.Black;
            }
            if (color == 4)
            {
                txtContentMsg.ForeColor = Color.Red;
            }
            if (color == 3)
            {
                txtContentMsg.ForeColor = Color.Yellow;
            }
            if (color == 2)
            {
                txtContentMsg.ForeColor = Color.Blue;
            }
            if (color == 1)
            {
                txtContentMsg.ForeColor = Color.Green;
            }
            txtContentMsg.AppendText(data);

        }

        public void WriteTextBoxOnlineUser(String name)
        {
            this.lstUser.Items.AddRange(new object[] { name });
        }

        protected void server_Closing(object sender, CancelEventArgs e)
        {

            System.Environment.Exit(System.Environment.ExitCode);
        }

        private void OpenPrivateRoom_Click(object sender, EventArgs e)
        {
            if (lstUser.SelectedIndex > -1)
            {
                this.OnNotifyPrivate(lstUser.SelectedItem.ToString());
            }
        }

        private void txtChat_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.OnNotifyDaddy(txtChat.Text);
                txtChat.Clear();
            }
        }

        private void btnBuzz_Click(object sender, EventArgs e)
        {
            EOffice.Business.Process.buzz(this.ParentForm, new System.Media.SoundPlayer(EOffice.Properties.Resources.Audiobuzz));
        }
    }
}



  

